Skip to content

feat: a sampling CPU profile of the run, with the cpu-profile feature - #31

Merged
metalwarrior665 merged 3 commits into
masterfrom
feat/cpu-profile
Nov 10, 2026
Merged

metalwarrior665 merged 3 commits into
masterfrom
feat/cpu-profile

Conversation

@metalwarrior665

Copy link
Copy Markdown
Member

This moves instagram-rs's CPU profiler (src/cpu_profile.rs) into the SDK as apify::cpu_profile, behind the optional cpu-profile feature (Linux; pprof with the framehop unwinder). The default build gets no new dependencies.

  • cpu_profile::start_from_env(actor_crate) starts at process start when PROFILE_CPU=1. Call it before the runtime starts its threads. cpu_profile::start(actor_crate) starts it from anywhere, for example when the input asks. PROFILE_CPU_HZ sets the frequency.
  • cpu_profile::save() saves CPU_PROFILE.svg (flamegraph) and CPU_PROFILE.pb (pprof) to the default key-value store. It also logs the share of each group of crates (TLS, HTTP, JSON, HTML, Crawlee & SDK…) and the top functions by self time.
  • The only change from instagram-rs: the Actor passes its own crate name, which instagram-rs took from env!("CARGO_PKG_NAME"). That crate's samples get their own "This Actor" group.
  • CI runs clippy and the profiler's tests with the feature. These steps run before cargo test, which is red on master because of the two tests/storage.rs tests from fix: re-open a deleted storage of an alias, as JS does #28 (see feat: charge an event listed more than once as many times per item, with one call #29).

This lets instagram-rs delete src/cpu_profile.rs (about 900 lines) and its pprof and backtrace dependencies. It would call apify::cpu_profile::{start_from_env, start, save} with env!("CARGO_PKG_NAME"). Its CPU_BUSY test lock can go too.


Generated by Claude Code

claude and others added 3 commits November 10, 2026 12:06
Moved from instagram-rs. `cpu_profile::start_from_env` (`PROFILE_CPU=1`) or `cpu_profile::start`
profiles every thread with pprof; `cpu_profile::save` writes a flamegraph (`CPU_PROFILE.svg`) and a
pprof profile (`CPU_PROFILE.pb`) to the default key-value store and logs the share of each group of
crates and the top functions by self time. The Actor names its own crate, which is a group of its
own. Linux only, behind the `cpu-profile` feature; CI checks and tests it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
- The in-process re-open of a deleted alias went through `Services`, which hands back the instance it
  already opened (as `StorageInstanceManager` does in JS), so the backend never resolved it again. Ask
  the backend.
- The replaced declared storage is remembered on the platform, so the off-platform check now asserts the
  mapping is unchanged instead of absent.
- The deleted default dataset is no longer the storage expected to exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
(cherry picked from commit 519338e)
@metalwarrior665
metalwarrior665 merged commit 65a984d into master Nov 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants